package helpdesk;

import database.Announcement;
import database.DatabaseInteraction;
import database.PDFHandler;
import database.Query;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JRadioButton;
import logindata.User;

public class GradAssInterface extends CenteredFrame {

    MyTableModel queryModel;
    MyTableModel announcementModel;
    Query[] queries;
    Announcement[] announcements;
    Object[][] queryData;
    Object[][] announcementData;

    public GradAssInterface(String _currentUser) {
        initComponents();
        currentUser = _currentUser;
        schedule = new database.Availability(currentUser);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        AvailabilityFrame = new CenteredFrame();
        dayDropdown = new javax.swing.JComboBox();
        am12 = new javax.swing.JRadioButton();
        am1 = new javax.swing.JRadioButton();
        am2 = new javax.swing.JRadioButton();
        am3 = new javax.swing.JRadioButton();
        am4 = new javax.swing.JRadioButton();
        am5 = new javax.swing.JRadioButton();
        am6 = new javax.swing.JRadioButton();
        am7 = new javax.swing.JRadioButton();
        am8 = new javax.swing.JRadioButton();
        am9 = new javax.swing.JRadioButton();
        am10 = new javax.swing.JRadioButton();
        am11 = new javax.swing.JRadioButton();
        pm12 = new javax.swing.JRadioButton();
        pm1 = new javax.swing.JRadioButton();
        pm2 = new javax.swing.JRadioButton();
        pm3 = new javax.swing.JRadioButton();
        pm4 = new javax.swing.JRadioButton();
        pm7 = new javax.swing.JRadioButton();
        pm6 = new javax.swing.JRadioButton();
        pm5 = new javax.swing.JRadioButton();
        pm8 = new javax.swing.JRadioButton();
        pm9 = new javax.swing.JRadioButton();
        pm10 = new javax.swing.JRadioButton();
        pm11 = new javax.swing.JRadioButton();
        availabilityUpdateBtn = new javax.swing.JButton();
        closeButton = new javax.swing.JButton();
        queRespFrame = new CenteredFrame();
        jScrollPane4 = new javax.swing.JScrollPane();
        viewQueRespTextArea = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        submitQueRespTextArea = new javax.swing.JTextArea();
        submitQueRespBtn = new javax.swing.JToggleButton();
        FormViewFrame = new CenteredFrame();
        jScrollPane6 = new javax.swing.JScrollPane();
        formList = new javax.swing.JList();
        reviewedButton = new javax.swing.JButton();
        formRefreshButton = new javax.swing.JButton();
        studentDropdown = new javax.swing.JComboBox();
        openFileButton = new javax.swing.JButton();
        submitQueryButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        cmboQuerySelect = new javax.swing.JComboBox();
        cmboCategorySelect = new javax.swing.JComboBox();
        viewSubmittedFormsBtn = new javax.swing.JButton();
        submitScheduleBtn = new javax.swing.JButton();
        replyToQueryBtn = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        submissionTextArea = new javax.swing.JEditorPane();
        queriesScrollPane = new javax.swing.JScrollPane();
        queriesTable = new javax.swing.JTable();
        announcementsScrollPane = new javax.swing.JScrollPane();
        announcementsTable = new javax.swing.JTable();

        dayDropdown.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        dayDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }));
        dayDropdown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dayDropdownActionPerformed(evt);
            }
        });

        am12.setText("12am-1am");

        am1.setText("1am-2am");

        am2.setText("2am-3am");

        am3.setText("3am-4am");

        am4.setText("4am-5am");

        am5.setText("5am-6am");

        am6.setText("6am-7am");

        am7.setText("7am-8am");

        am8.setText("8am-9am");

        am9.setText("9-10am");

        am10.setText("10-11am");

        am11.setText("11-12pm");

        pm12.setText("12-1pm");

        pm1.setText("1-2pm");

        pm2.setText("2-3pm");

        pm3.setText("3-4pm");

        pm4.setText("4-5pm");

        pm7.setText("7-8pm");

        pm6.setText("6-7pm");
        pm6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pm6ActionPerformed(evt);
            }
        });

        pm5.setText("5-6pm");

        pm8.setText("8-9pm");

        pm9.setText("9-10pm");

        pm10.setText("10-11pm");

        pm11.setText("11-12am");

        availabilityUpdateBtn.setText("Update");
        availabilityUpdateBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                availabilityUpdateBtnActionPerformed(evt);
            }
        });

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout AvailabilityFrameLayout = new org.jdesktop.layout.GroupLayout(AvailabilityFrame.getContentPane());
        AvailabilityFrame.getContentPane().setLayout(AvailabilityFrameLayout);
        AvailabilityFrameLayout.setHorizontalGroup(
            AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(AvailabilityFrameLayout.createSequentialGroup()
                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(AvailabilityFrameLayout.createSequentialGroup()
                        .add(260, 260, 260)
                        .add(dayDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(availabilityUpdateBtn)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(closeButton))
                    .add(AvailabilityFrameLayout.createSequentialGroup()
                        .add(53, 53, 53)
                        .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(am12)
                            .add(am7)
                            .add(pm2)
                            .add(pm9))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(AvailabilityFrameLayout.createSequentialGroup()
                                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(AvailabilityFrameLayout.createSequentialGroup()
                                        .add(am1)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(am2))
                                    .add(AvailabilityFrameLayout.createSequentialGroup()
                                        .add(am8)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(am9)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(am3)
                                    .add(am10))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(AvailabilityFrameLayout.createSequentialGroup()
                                        .add(am4)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(am5))
                                    .add(AvailabilityFrameLayout.createSequentialGroup()
                                        .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(am11)
                                            .add(pm6))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(pm7)
                                            .add(pm12)))))
                            .add(AvailabilityFrameLayout.createSequentialGroup()
                                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(pm3)
                                    .add(pm10))
                                .add(4, 4, 4)
                                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(pm11)
                                    .add(AvailabilityFrameLayout.createSequentialGroup()
                                        .add(pm4)
                                        .add(18, 18, 18)
                                        .add(pm5)))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(pm1)
                            .add(am6)
                            .add(pm8))))
                .addContainerGap(87, Short.MAX_VALUE))
        );
        AvailabilityFrameLayout.setVerticalGroup(
            AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(AvailabilityFrameLayout.createSequentialGroup()
                .add(44, 44, 44)
                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(dayDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(availabilityUpdateBtn)
                    .add(closeButton))
                .add(22, 22, 22)
                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(am12)
                    .add(am1)
                    .add(am2)
                    .add(am3)
                    .add(am4)
                    .add(am5)
                    .add(am6))
                .add(18, 18, 18)
                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(am7)
                    .add(am8)
                    .add(am9)
                    .add(am11)
                    .add(pm12)
                    .add(pm1)
                    .add(am10))
                .add(18, 18, 18)
                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(pm2)
                    .add(pm3)
                    .add(pm4)
                    .add(pm5)
                    .add(pm6)
                    .add(pm7)
                    .add(pm8))
                .add(18, 18, 18)
                .add(AvailabilityFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(pm9)
                    .add(pm10)
                    .add(pm11))
                .addContainerGap(76, Short.MAX_VALUE))
        );

        viewQueRespTextArea.setColumns(20);
        viewQueRespTextArea.setEditable(false);
        viewQueRespTextArea.setLineWrap(true);
        viewQueRespTextArea.setRows(5);
        viewQueRespTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Query"));
        jScrollPane4.setViewportView(viewQueRespTextArea);

        submitQueRespTextArea.setColumns(20);
        submitQueRespTextArea.setRows(5);
        submitQueRespTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Response"));
        jScrollPane5.setViewportView(submitQueRespTextArea);

        submitQueRespBtn.setText("Submit");
        submitQueRespBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitQueRespBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout queRespFrameLayout = new org.jdesktop.layout.GroupLayout(queRespFrame.getContentPane());
        queRespFrame.getContentPane().setLayout(queRespFrameLayout);
        queRespFrameLayout.setHorizontalGroup(
            queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(queRespFrameLayout.createSequentialGroup()
                .add(14, 14, 14)
                .add(queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane4)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, submitQueRespBtn))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        queRespFrameLayout.setVerticalGroup(
            queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(queRespFrameLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(submitQueRespBtn)
                .addContainerGap())
        );

        FormViewFrame.setTitle("View Forms");
        FormViewFrame.setBounds(new java.awt.Rectangle(0, 22, 400, 200));
        FormViewFrame.setFocusCycleRoot(false);
        FormViewFrame.setForeground(java.awt.Color.white);
        FormViewFrame.setMinimumSize(new java.awt.Dimension(200, 300));
        FormViewFrame.setResizable(false);

        formList.setBorder(javax.swing.BorderFactory.createTitledBorder("Unreviewed Form Submissions"));
        jScrollPane6.setViewportView(formList);

        reviewedButton.setText("Set Reviewed");
        reviewedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reviewedButtonActionPerformed(evt);
            }
        });

        formRefreshButton.setText("Refresh");
        formRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formRefreshButtonActionPerformed(evt);
            }
        });

        studentDropdown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                studentDropdownActionPerformed(evt);
            }
        });

        openFileButton.setText("Open File");
        openFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openFileButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout FormViewFrameLayout = new org.jdesktop.layout.GroupLayout(FormViewFrame.getContentPane());
        FormViewFrame.getContentPane().setLayout(FormViewFrameLayout);
        FormViewFrameLayout.setHorizontalGroup(
            FormViewFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(FormViewFrameLayout.createSequentialGroup()
                .add(FormViewFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, studentDropdown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(FormViewFrameLayout.createSequentialGroup()
                        .add(FormViewFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(FormViewFrameLayout.createSequentialGroup()
                                .add(21, 21, 21)
                                .add(formRefreshButton))
                            .add(FormViewFrameLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(reviewedButton))
                            .add(FormViewFrameLayout.createSequentialGroup()
                                .add(23, 23, 23)
                                .add(openFileButton)))
                        .add(0, 59, Short.MAX_VALUE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 216, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        FormViewFrameLayout.setVerticalGroup(
            FormViewFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(FormViewFrameLayout.createSequentialGroup()
                .add(FormViewFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(FormViewFrameLayout.createSequentialGroup()
                        .add(35, 35, 35)
                        .add(studentDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(21, 21, 21)
                        .add(openFileButton)
                        .add(18, 18, 18)
                        .add(reviewedButton)
                        .add(18, 18, 18)
                        .add(formRefreshButton))
                    .add(FormViewFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 294, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Help Desk - Graduate Assistant");
        setMinimumSize(new java.awt.Dimension(671, 537));

        submitQueryButton.setText("Submit");
        submitQueryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitQueryButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Options"));

        cmboQuerySelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All Types", "Student Queries", "Assistant Queries" }));
        cmboQuerySelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmboQuerySelectActionPerformed(evt);
            }
        });

        cmboCategorySelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All Categories", "Response to an Announcement", "Regarding Form Submission", "Rearding Help Desk", "Other" }));
        cmboCategorySelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmboCategorySelectActionPerformed(evt);
            }
        });

        viewSubmittedFormsBtn.setText("View submitted forms");
        viewSubmittedFormsBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewSubmittedFormsBtnActionPerformed(evt);
            }
        });

        submitScheduleBtn.setText("Submit Schedule");
        submitScheduleBtn.setMaximumSize(new java.awt.Dimension(157, 25));
        submitScheduleBtn.setMinimumSize(new java.awt.Dimension(157, 25));
        submitScheduleBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitScheduleBtnActionPerformed(evt);
            }
        });

        replyToQueryBtn.setText("Reply to Query");
        replyToQueryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                replyToQueryBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(submitScheduleBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, viewSubmittedFormsBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, cmboQuerySelect, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(replyToQueryBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(cmboCategorySelect, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(cmboQuerySelect, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cmboCategorySelect, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(replyToQueryBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(viewSubmittedFormsBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(submitScheduleBtn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(0, 0, Short.MAX_VALUE))
        );

        submissionTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Post Announcement"));
        submissionTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane2.setViewportView(submissionTextArea);

        queriesScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Queries"));

        queryModel = new MyTableModel();//DefaultTableModel();
        queriesTable.setModel(queryModel);
        queriesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        queriesTable.setAutoscrolls(false);
        queriesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        queriesTable.getTableHeader().setReorderingAllowed(false);
        queriesScrollPane.setViewportView(queriesTable);
        updateQueries();

        announcementsScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Announcements"));

        announcementModel = new MyTableModel();
        announcementsTable.setModel(announcementModel);
        announcementsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        announcementsTable.setAutoscrolls(false);
        announcementsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        announcementsTable.getTableHeader().setReorderingAllowed(false);
        announcementsScrollPane.setViewportView(announcementsTable);
        updateAnnouncement();

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(48, 48, 48)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(12, 12, 12)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(submitQueryButton)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, queriesScrollPane))
                        .add(16, 16, 16))
                    .add(layout.createSequentialGroup()
                        .add(announcementsScrollPane)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(announcementsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 157, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(queriesScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 162, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(9, 9, 9)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(submitQueryButton))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void submitScheduleBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitScheduleBtnActionPerformed
        AvailabilityFrame.setSize(730, 300);
        AvailabilityFrame.setVisible(true);
        updateTimeButtons();
    }//GEN-LAST:event_submitScheduleBtnActionPerformed

    private void pm6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pm6ActionPerformed
    }//GEN-LAST:event_pm6ActionPerformed

    private void updateTimeButtons() {
        schedule = DatabaseInteraction.getAvailability(schedule.getUsername());
        JRadioButton[] timeButtons = {am12, am1, am2, am3, am4, am5, am6, am7, am8,
            am9, am10, am11, pm12, pm1, pm2, pm3, pm4, pm5, pm6, pm7, pm8, pm9,
            pm10, pm11};
        database.Day day = schedule.getDay(dayDropdown.getSelectedIndex());
        for (int i = 0; i < timeButtons.length; i++) {
            timeButtons[i].setSelected(day.times[i]);
        }
    }

    private void setAvailability() {
        JRadioButton[] timeButtons = {am12, am1, am2, am3, am4, am5, am6, am7, am8,
            am9, am10, am11, pm12, pm1, pm2, pm3, pm4, pm5, pm6, pm7, pm8, pm9,
            pm10, pm11};
        schedule.setUsername(currentUser);
        database.Day day = schedule.getDay(dayDropdown.getSelectedIndex());
        for (int i = 0; i < timeButtons.length; i++) {
            day.times[i] = timeButtons[i].isSelected();
        }
        schedule.setDay(dayDropdown.getSelectedIndex(), day);
        DatabaseInteraction.postAvailability(schedule);
    }

    private void dayDropdownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dayDropdownActionPerformed
        updateTimeButtons();
    }//GEN-LAST:event_dayDropdownActionPerformed

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        AvailabilityFrame.setVisible(false);
    }//GEN-LAST:event_closeButtonActionPerformed

    private void availabilityUpdateBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_availabilityUpdateBtnActionPerformed
        setAvailability();

    }//GEN-LAST:event_availabilityUpdateBtnActionPerformed

    private void submitQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitQueryButtonActionPerformed
        String createdby, content;
        if (!submissionTextArea.getText().equals("")) {
            createdby = currentUser;
            content = submissionTextArea.getText();
            Announcement announce = new Announcement(createdby, content);
            DatabaseInteraction.postAnnouncement(announce);
            updateAnnouncement();
            submissionTextArea.setText("");
        }
    }//GEN-LAST:event_submitQueryButtonActionPerformed
    private void updateAnnouncement() {
        announcements = DatabaseInteraction.getAllAnnouncements();
        announcementData = new Object[announcements.length][2];
        for (int i = 0; i < announcements.length; i++) {
            announcementData[i][0] = announcements[i].getCreateBy();
            announcementData[i][1] = announcements[i].getContent();
        }
        announcementModel.setDataVector(announcementData, new Object[]{"User", "Announcment"});
        announcementsTable.setModel(announcementModel);
        announcementsTable.getTableHeader().setReorderingAllowed(false);
        announcementsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        javax.swing.table.TableColumn col = announcementsTable.getColumnModel().getColumn(0);
        col.setPreferredWidth(100);
        javax.swing.table.TableColumn col2 = announcementsTable.getColumnModel().getColumn(1);
        col2.setPreferredWidth(1000);
    }

    private void replyToQueryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replyToQueryBtnActionPerformed
        if (queriesTable.isRowSelected(queriesTable.getSelectedRow())) {
            queRespFrame.setSize(500, 350);
            queRespFrame.setVisible(true);
            String content = queries[queriesTable.getSelectedRow()].get("content").toString();
            String username = queries[queriesTable.getSelectedRow()].get("createdBy").toString();
            String responses = queries[queriesTable.getSelectedRow()].get("responses").toString();
            if (responses.length() > 0) {
                responses += "\n";
            }
            viewQueRespTextArea.setText(username + ": " + content);
            submitQueRespTextArea.setText(responses + currentUser + ": ");
        }
    }//GEN-LAST:event_replyToQueryBtnActionPerformed

    private void submitQueRespBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitQueRespBtnActionPerformed
        int id = Integer.parseInt(queries[queriesTable.getSelectedRow()].get("id").toString());
        DatabaseInteraction.editQuery(id, "responses", submitQueRespTextArea.getText());
        updateQueries();
        queRespFrame.dispose();
    }//GEN-LAST:event_submitQueRespBtnActionPerformed

    private void viewSubmittedFormsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewSubmittedFormsBtnActionPerformed
        FormViewFrame.setSize(450, 500);
        FormViewFrame.setVisible(true);
        refreshFormList();
    }//GEN-LAST:event_viewSubmittedFormsBtnActionPerformed

    private void formRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formRefreshButtonActionPerformed
        refreshFormList();
    }//GEN-LAST:event_formRefreshButtonActionPerformed

    private void reviewedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reviewedButtonActionPerformed
        if (!formList.isSelectionEmpty()) {
            String filename = files[formList.getSelectedIndex()];
            DatabaseInteraction.updateFormReviewStatus((String) studentDropdown.getSelectedItem(), filename, 1);
            refreshFormList();
        }
    }//GEN-LAST:event_reviewedButtonActionPerformed

    private void studentDropdownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_studentDropdownActionPerformed
        refreshFormList();
    }//GEN-LAST:event_studentDropdownActionPerformed

    private void openFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFileButtonActionPerformed

        try {
            String filename = files[formList.getSelectedIndex()];
            if (filename != null) {
                File file = DatabaseInteraction.getSelectedForm(currentUser,
                        filename);
                PDFHandler.open(file);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(GradAssInterface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(GradAssInterface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ArrayIndexOutOfBoundsException e) {
            Logger.getLogger(GradAssInterface.class.getName()).log(Level.SEVERE, null, e);
        }

    }//GEN-LAST:event_openFileButtonActionPerformed

    private void cmboQuerySelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmboQuerySelectActionPerformed
        updateQueries();
    }//GEN-LAST:event_cmboQuerySelectActionPerformed

    private void cmboCategorySelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmboCategorySelectActionPerformed
        updateQueries();
    }//GEN-LAST:event_cmboCategorySelectActionPerformed

    private void updateQueries() {
        queries = DatabaseInteraction.getAllQueries();
        ArrayList<Query> queries2 = new ArrayList<Query>();
        int valueType, valueCategory;
        for (int i = 0; i < queries.length; i++) {
            if ((queries[i].get("typeViewable").equals(cmboQuerySelect.getSelectedIndex()) || cmboQuerySelect.getSelectedIndex() == 0)
                    && (queries[i].get("category").equals(cmboCategorySelect.getSelectedIndex()) || cmboCategorySelect.getSelectedIndex() == 0)) {
                queries2.add(queries[i]);
            }
        }
        queries = queries2.toArray(new Query[queries2.size()]);
        queryData = new Object[queries.length][2];
        for (int i = 0; i < queries.length; i++) {
            queryData[i][0] = queries[i].get("createdby");
            queryData[i][1] = queries[i].get("content");
        }
        queryModel.setDataVector(queryData, new Object[]{"User", "Query"});
        queriesTable.setModel(queryModel);
        queriesTable.setColumnSelectionAllowed(false);
        queriesTable.setMaximumSize(new java.awt.Dimension(1000, 500));
        queriesTable.setMinimumSize(new java.awt.Dimension(500, 100));
        queriesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        queriesTable.getTableHeader().setReorderingAllowed(false);
        queriesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        javax.swing.table.TableColumn col = queriesTable.getColumnModel().getColumn(0);
        col.setPreferredWidth(100);
        javax.swing.table.TableColumn col2 = queriesTable.getColumnModel().getColumn(1);
        col2.setPreferredWidth(1000);
        queriesScrollPane.setViewportView(queriesTable);
        queriesTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    }

    private void refreshFormList() {
        int index = studentDropdown.getSelectedIndex();
        files = DatabaseInteraction.getAllUnreviewedForms((String) studentDropdown.getSelectedItem());
        formList.setListData(files);
        users = DatabaseInteraction.getAllUsers();
        ArrayList<String> temp = new ArrayList<String>();
        for (int i = 0; i < users.length; i++) {
            if (users[i].getPermissions() == 1) {
                temp.add(users[i].getUserName());
            }
        }
        studentDropdown.setModel(new javax.swing.DefaultComboBoxModel(temp.toArray()));
        studentDropdown.setSelectedIndex(index);
    }
    private String currentUser;
    database.Availability schedule;
    String[] files;
    User[] users;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame AvailabilityFrame;
    private javax.swing.JFrame FormViewFrame;
    private javax.swing.JRadioButton am1;
    private javax.swing.JRadioButton am10;
    private javax.swing.JRadioButton am11;
    private javax.swing.JRadioButton am12;
    private javax.swing.JRadioButton am2;
    private javax.swing.JRadioButton am3;
    private javax.swing.JRadioButton am4;
    private javax.swing.JRadioButton am5;
    private javax.swing.JRadioButton am6;
    private javax.swing.JRadioButton am7;
    private javax.swing.JRadioButton am8;
    private javax.swing.JRadioButton am9;
    private javax.swing.JScrollPane announcementsScrollPane;
    private javax.swing.JTable announcementsTable;
    private javax.swing.JButton availabilityUpdateBtn;
    private javax.swing.JButton closeButton;
    private javax.swing.JComboBox cmboCategorySelect;
    private javax.swing.JComboBox cmboQuerySelect;
    private javax.swing.JComboBox dayDropdown;
    private javax.swing.JList formList;
    private javax.swing.JButton formRefreshButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JButton openFileButton;
    private javax.swing.JRadioButton pm1;
    private javax.swing.JRadioButton pm10;
    private javax.swing.JRadioButton pm11;
    private javax.swing.JRadioButton pm12;
    private javax.swing.JRadioButton pm2;
    private javax.swing.JRadioButton pm3;
    private javax.swing.JRadioButton pm4;
    private javax.swing.JRadioButton pm5;
    private javax.swing.JRadioButton pm6;
    private javax.swing.JRadioButton pm7;
    private javax.swing.JRadioButton pm8;
    private javax.swing.JRadioButton pm9;
    private javax.swing.JFrame queRespFrame;
    private javax.swing.JScrollPane queriesScrollPane;
    private javax.swing.JTable queriesTable;
    private javax.swing.JButton replyToQueryBtn;
    private javax.swing.JButton reviewedButton;
    private javax.swing.JComboBox studentDropdown;
    private javax.swing.JEditorPane submissionTextArea;
    private javax.swing.JToggleButton submitQueRespBtn;
    private javax.swing.JTextArea submitQueRespTextArea;
    private javax.swing.JButton submitQueryButton;
    private javax.swing.JButton submitScheduleBtn;
    private javax.swing.JTextArea viewQueRespTextArea;
    private javax.swing.JButton viewSubmittedFormsBtn;
    // End of variables declaration//GEN-END:variables
}
